﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace MyService
{
    public class Log
    {
        /// <summary>
        /// 写入服务日志
        /// </summary>
        /// <param name="strMsg"></param>
        public static void WriteLog(string strMsg)
        {
            try
            {
                strMsg = "\r\n==================" + strMsg + "===============\r\n";
                string logDirectory = AppDomain.CurrentDomain.BaseDirectory + "\\Logs";
                if (!Directory.Exists(logDirectory))
                {
                    Directory.CreateDirectory(logDirectory);
                }
                string filePath = logDirectory + "\\" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt";
                File.AppendAllText(filePath, strMsg);
            }
            catch (Exception)
            {
                throw;
            }
        }
    }
}
